package com.powerhua.cms.persistence.file;

import com.powerhua.core.utils.WebPathUtils;
import java.io.File;

public class CmsFileManagerImpl implements CmsFileManager {

	public File getContentFile(String contentId) {
		if (contentId.length() < 6) {
			return null;
		}

		String fileSep = System.getProperty("file.separator");
		String cmsFileBasePath = WebPathUtils.getWebInfPath() + fileSep
				+ "cms_docs";
		String path1 = contentId.substring(0, 2);
		String path2 = contentId.substring(2, 4);
		String path3 = contentId.substring(4, 6);
		
		String folderPath = cmsFileBasePath + fileSep + path1 + fileSep
			+ path2 + fileSep + path3;
		File folder = new File(folderPath);
		if (!folder.exists()) {
			folder.mkdirs();
		}
		
		File file = new File(folderPath + fileSep + contentId);

		return file;
	}

}
